<?php

namespace backend\controllers;
use common\models\Log;
use common\service\ConstantService;

class LogController extends BaseController
{
    //显示日志页面
    public function actionIndex(){
        if($this->isAjax() && $this->isAjax()){
            $query=Log::find();

            if (!empty($this->get('admin_name'))){
                $query->andWhere(['like','admin_name',$this->get('admin_name')]);
            }
            if (!empty($this->get('start_time'))){
                $query->andWhere(['>=','log_time',strtotime($this->get('start_time'))]);
            }
            if (!empty($this->get('end_time'))){
                $query->andWhere(['<=','log_time',strtotime($this->get('end_time'))]);
            }
            $p = intval( $this->get('page',1) );
            $this->page_size = intval( $this->get('limit',10) );

            $p = ( $p > 0 )? $p : 1;
            $count = $query->count();
            $offset = ($p - 1) * $this->page_size;
            $data = $query->offset($offset)
                ->limit($this->page_size)
                ->orderBy(['log_time'=> SORT_DESC])
                ->asArray()
                ->all();
            return $this->renderPageJson($data,$count,ConstantService::$response_tab_success);


        }
        return $this->render('index');
    }


}